package com.example.qxfw.dataBaseManager.nyzjk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.entity.ny.Diseasedatalib;
import com.example.qxfw.common.entity.ny.StationInfo;
import com.example.qxfw.common.mapper.DiseasedatalibMapperXml;
import com.example.qxfw.common.mapper.StationInfoMapperXml;
import com.example.qxfw.dataBaseManager.nyzjk.service.LsbchzlkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/5  星期三   23:28
 * @description : 此类用来
 ***************************************/
@Service
public class LsbchzlkServiceImpl implements LsbchzlkService {

    @Autowired
    private DiseasedatalibMapperXml diseasedatalibMapperXml;

    @Autowired
    private StationInfoMapperXml stationInfoMapperXml;

    @Override
    public List<Diseasedatalib> getAllDiseaseDataLib() {
        List<Diseasedatalib> diseasedatalibList = this.diseasedatalibMapperXml.selectList(null);
        return diseasedatalibList;
    }

    @Override
    public List<StationInfo> getAllStationInfo() {
        return this.stationInfoMapperXml.selectList(null);
    }

    @Override
    public List<Diseasedatalib> selectDistinctCropName(String column,String cropname) {
        List<Diseasedatalib> diseasedatalibs = this.diseasedatalibMapperXml.selectDistinct(column,cropname);
        return diseasedatalibs;
    }

    @Override
    public Integer saveDiseaseDataLib(final Diseasedatalib diseasedatalib) {
        int insert = this.diseasedatalibMapperXml.insertSelective(diseasedatalib);
        return insert;
    }

    @Override
    public Integer updateDiseaseDataLib(final Diseasedatalib diseasedatalib) {
        Diseasedatalib diseasedatalib1 = new Diseasedatalib();
        diseasedatalib1.setCropname(diseasedatalib.getCropname());
        diseasedatalib1.setType(diseasedatalib.getType());
        diseasedatalib1.setDiseasesname(diseasedatalib.getDiseasesname());
        diseasedatalib1.setStarttime(diseasedatalib.getStarttime());
        diseasedatalib1.setEndtime(diseasedatalib.getEndtime());
        diseasedatalib1.setInfluencearea(diseasedatalib.getInfluencearea());
        diseasedatalib1.setLostmoney(diseasedatalib.getLostmoney());
        diseasedatalib1.setInfluencedescribe(diseasedatalib.getInfluencedescribe());
        return this.diseasedatalibMapperXml.update(diseasedatalib, Wrappers.<Diseasedatalib>lambdaUpdate(diseasedatalib1));
    }

    @Override
    public Integer deleteDiseaseDataLib(final Diseasedatalib diseasedatalib) {
        QueryWrapper<Diseasedatalib> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .lambda()
                .eq(Diseasedatalib::getStationid, diseasedatalib.getStationid())
                .eq(Diseasedatalib::getCropname, diseasedatalib.getCropname())
                .eq(Diseasedatalib::getType, diseasedatalib.getType())
                .eq(Diseasedatalib::getStarttime, diseasedatalib.getStarttime())
                .eq(Diseasedatalib::getEndtime, diseasedatalib.getEndtime())
                .eq(Diseasedatalib::getInfluencearea, diseasedatalib.getInfluencearea())
                .eq(Diseasedatalib::getLostmoney, diseasedatalib.getLostmoney())
                .eq(Diseasedatalib::getInfluencedescribe, diseasedatalib.getInfluencedescribe());
        return this.diseasedatalibMapperXml.delete(queryWrapper);
    }
}
